
package {
    import flash.display.Sprite;    
    
    /**
     * @author Christian Rauh
     */
    public class ParticleConnection extends Sprite {
    	
    	public var strength : Number;
    	
    	protected var p1 : Particle;
    	protected var p2 : Particle;
    	protected var lineSprite : Sprite;
    	
    	public function ParticleConnection(p1: Particle, p2:Particle, strength:Number) {
    		
    		this.p1 = p1;
    		this.p2 = p2;
            this.strength = strength;
            
            lineSprite = new Sprite();
            lineSprite.graphics.beginFill(0xaa9933, 1);
			lineSprite.graphics.drawRect(0, 0, 100, 1);
			lineSprite.alpha = strength / 5;
			
			visible = false;
			
			addChild(lineSprite);	
        }
        
        public function update():void {
        	
        	lineSprite.alpha = strength / 5;
        	
        	x = p1.x;
        	y = p1.y;
        	var distance : Number = p1.distance(p2);
        	if (distance != 0) {
        		lineSprite.width = Math.abs(distance);
        	}
        	
        	rotation = p1.angle(p2) * 180 / Math.PI;
        	
        	visible = true;
        }
    }
}
